<template>
    <div class="count">
        <h2>当前求和为: {{ sum }}, 放大: {{ doubleSum }} </h2>
        <h2>字符串: {{ word }}, 加长: {{ longWord }} </h2>
        <select v-model.number="n">
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
        </select>
        <button @click="add">加</button>
        <button @click="minus">减</button>
    </div>
</template>
<script lang="ts" setup name="Count">
import { ref } from 'vue';
import { useCountStore } from '@/store/count';
import { storeToRefs } from 'pinia';

const n = ref(1)

const countStore = useCountStore();
// storeToRefs,相对于toRefs的优势: toRefs会包裹所有属性,包括store中的数据和方法,而storeToRefs只会包裹store中的数据
const { sum, word, doubleSum, longWord } = storeToRefs(countStore)
function add() {
    countStore.increment(n.value)
}
function minus() {
    countStore.decrement(n.value)
}
</script>
<style scoped>
.count {
    background-color: skyblue;
    padding: 10px;
    border-radius: 10px;
    box-shadow: 0 0 10px;
}

select,
button {
    margin: 0 5px;
    height: 25px;
}
</style>